'''
触发: raise 异常
断言: assert 真值表达式，错误信息（通常是字符串）

'''

import random
ran = random.random()
#模拟盖房子
def f1():
    print("开始打地基…………")
    if ran < 0.3:
        raise ValueError("打到地下水了")
    elif ran > 0.8:
        raise ZeroDivisionError("打斜了")

    print("打地基结束…………")
try:
    f1()
except ValueError:
    print("打到地下水了")
except ZeroDivisionError:
    print("打斜了")

# f1()

ran = random.random()
def f2():
    print("开始盖房子了………………")

    assert ran >0.8,"太高了，附近有飞机场"

    assert ran < 0.3,"太矮了，人在里面太难受了"

    print("房子盖完了……………………")

try:
    f2()
except AssertionError as a:
    print(a)